﻿Imports Microsoft.VisualBasic

Public Class MyDataView
    Public Shared PublicProgram As New SelectStringBuilder("Program p")
    Public Shared ProtectedProgram As New SelectStringBuilder("Program p")
    Public Shared User As New SelectStringBuilder("Employee e")
    Public Shared InternalUser As New SelectStringBuilder("Employee e")
    Public Shared OrganizationView As New SelectStringBuilder("Organization o")
    Public Shared OrganizationTree As New SelectStringBuilder("Organization o")
    Public Shared RoleUserMappingView As New SelectStringBuilder("RoleUserMapping ru")
    Public Shared RoleProgramMappingView As New SelectStringBuilder("RoleProgramMapping rp")

    Shared Sub New()

        '
        PublicProgram.AddColumn("p.* ")
        PublicProgram.AddCondition("p.ProgramType", "Public")

        '
        ProtectedProgram.AddColumn("p.* ")
        ProtectedProgram.AddCondition("p.ProgramType", "Protected")

        '
        User.AddColumn("EmployeeID AS UserID, EmployeeName AS UserName, WindowsID, e.Active, 'E' as UserType")

        '
        InternalUser.AddColumn("EmployeeID AS UserID, EmployeeName AS UserName, WindowsID, Active, 'E' as UserType")
        InternalUser.AddColumn("cast(OrganizationID as char(50))+','+'-1' as UOrganizationID")

        '
        OrganizationView.AddColumn("cast(o.OrganizationID as char(50))+','+'-1' as UOrganizationID,cast(o.OrganizationID as char(50))+','+'-1' as ID, o.OrganizationID, -1 as VOrganizationID, o.OrganizationName, o.Parent, null as VParent, o.Active, o.OrganizationCode, null as VOrganizationCode, 'O' as OrganizationType")

        '
        OrganizationTree.AddColumn("cast(o.OrganizationID as char(50))+','+'-1' as UOrganizationID,cast(o.OrganizationID as char(50))+','+'-1' as ID, o.OrganizationID, -1 as VOrganizationID, o.OrganizationName, o.Parent, null as VParent, o.Active ")
        OrganizationTree.AddColumn("o_parent.OrganizationID AS Root, -1 as VRoot, cast(o_parent.OrganizationID as char(50))+','+'-1' as URoot")
        OrganizationTree.AddColumn("'O' as OrganizationType")
        OrganizationTree.InnerJoin("Organization o_parent", "1", "1")
        OrganizationTree.Relations(0).AddCondition("o.OrganizationCode", MyEqualityOperator.MyLike, New MyCompositeExpression(New MyColumnExpression("o_parent.OrganizationCode"), MyArithmeticOperator.Add, New MyValueExpression("%")))
        OrganizationTree.Relations(0).OrCondition("o.InternalCode", MyEqualityOperator.MyLike, New MyCompositeExpression(New MyColumnExpression("o_parent.InternalCode"), MyArithmeticOperator.Add, New MyValueExpression("_%")))
        '
        RoleUserMappingView.AddColumn("ru.*, r.RoleName, r.RoleDescription, r.Parent")
        RoleUserMappingView.InnerJoin("Role r", "ru.RoleID", "r.RoleID")
        RoleUserMappingView.AddCondition("Active", "Y")

        RoleProgramMappingView.AddColumn("rp.*")
        RoleProgramMappingView.InnerJoin("Role r", "rp.RoleID", "r.RoleID")
        RoleProgramMappingView.AddCondition("Active", "Y")
    End Sub

End Class
